//
//  MyOrderViewController.m
//  JxCarios
//
//  Created by phev on 15/3/3.
//  Copyright (c) 2015年 xiongchuanqi. All rights reserved.
//

#import "MyOrderViewController.h"
#import "CarAroundDataSource.h"
#import "ScopeConverViewController.h"
#import "PullDownListViewController.h"

@interface MyOrderViewController (){
    CarAroundDataSource *carAround;
    NSMutableDictionary *dataSource;
}

@end

@implementation MyOrderViewController


- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
    UIView *btn = (UIView *)[self.tabBarController.view  viewWithTag:400];
    btn.hidden = YES;
}

- (void)backTo {
    self.tabBarController.tabBar.hidden = NO;
    UIView *btn = (UIView *)[self.tabBarController.view  viewWithTag:400];
    UIView *popView = (UIView*)[self.tabBarController.view viewWithTag:511];
    btn.hidden = NO;
    [self.tabBarController.view bringSubviewToFront:btn];
    [self.tabBarController.view bringSubviewToFront:popView];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initAbout];
    [self setUpViewClick];
    [self netRequest];
}

- (void)netRequest {
    
    if (!carAround) {
        carAround = [CarAroundDataSource dataSourceWithRequestor:self];
    }
    
    [carAround getMyOrder:^(id result) {
        dataSource = result;
        [self initDataSource];
    } anfFail:^(id result) {
        
    }];
}
/*
 *outline	3	当面付订单
 online	3	线上付订单
 pay_no	4	未支付订单
 pay_yes	6	已支付订单
 finish   	8	已服务完成订单
 drawback	1	退款订单
 oilcard	0	油卡订单
 vbmail	8	积分兑换订单
 */

- (void)initDataSource {
    NSArray *keyArr = @[@"vbmail",@"outline",@"online",@"drawback",@"finish",@"oilcard",@"pay_no",@"pay_yes"];
    int i = 0;
    for (UILabel *label in _titleArr) {
        label.text = [dataSource customObjectForkey:[keyArr objectAtIndex:i]];
        i ++;
    }
}


- (void)setUpViewClick {
    
    for (UIView *view in _orderArr) {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [tap addTarget:self action:@selector(pushOrderDetail:)];
        [view addGestureRecognizer:tap];
    }
}

- (void)pushOrderDetail:(UIGestureRecognizer *)sender {
     int index = sender.view.tag % 100;
    if (index == 0 || index == 1 || index == 2) {
        ScopeConverViewController *scope = [[ScopeConverViewController alloc] initWithNibName:@"ScopeConverViewController" bundle:nil];
        if(index == 0){
            scope.type = 4; //积分兑换
        }else if (index == 1) {
            scope.type = 6; ////当面付
        }else {
            scope.type = 5; //线上支付
        }
        
        [self.navigationController pushViewController:scope animated:YES];
    }else {
        PullDownListViewController *pull  = nil;
        if (index == 3) { //退款订单
            pull = [[PullDownListViewController alloc] init:refund];
        }else if (index == 4) { //已完成订单
            pull = [[PullDownListViewController alloc] init:OkValue];
        }else { //油卡订单
            pull = [[PullDownListViewController alloc] init:OilCard];
        }
        
        [self.navigationController pushViewController:pull animated:YES];
    }
}


- (void)initAbout {
    self.title = @"我的订单";
    [self showNavBarWithRightTitle:nil andRightAction:nil andLeftAction:nil andCustom:NO];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
